package 厦门大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import 南京理工大学.NJuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class XMu {
    public static void main(String[] args) throws IOException {
        XMuBean xMuBean;
        List<XMuBean> xMuBeans = new ArrayList<>();
        String Url = "https://energy.xmu.edu.cn/szll/jsdw.htm";
        String a_p = null;
        Connection connect = Jsoup.connect(Url);
        Document post = connect.post();
        Elements ul = post.getElementsByTag("ul");
        for (Element element : ul) {
            for (Element elementsByClass : element.getElementsByClass("col-xs-6 col-sm-6 col-md-3")) {
                Elements elementsByClass1 = elementsByClass.getElementsByClass("col-xs-6 col-sm-6 col-md-3");
                xMuBean = new XMuBean();
                xMuBean.setT_name(elementsByClass1.text());
                for (Element element1 : elementsByClass1) {
                    String attr = element1.getElementsByTag("a").attr("href");
                    a_p = attr.substring(3, attr.length());
                    String url = "https://energy.xmu.edu.cn/" + a_p;
                    Connection connect1 = Jsoup.connect(url);
                    Document post1 = connect1.post();
                    for (Element byClass : post1.getElementsByClass("col-xs-12 col-sm-12 col-md-9 col-lg-9")) {
                        for (Element p : byClass.getElementsByTag("p")) {
//                            p.text();//info
                            xMuBean.setInfo(p.text());
                        }

                    }

                }
                xMuBeans.add(xMuBean);
            }

        }
        EasyExcel.write("src/XMU.xlsx", XMuBean.class).sheet("user").doWrite(xMuBeans);

    }
}
